package com.example.payment.model.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 支付记录实体类
 * 对应数据库表 t_payment
 * 
 * @author mall-team
 */
@Entity
@Table(name = "t_payment")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Payment {

    /**
     * 支付ID（主键）
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 支付流水号（业务主键，全局唯一）
     */
    @Column(name = "payment_no", nullable = false, unique = true, length = 64)
    private String paymentNo;

    /**
     * 订单编号
     */
    @Column(name = "order_no", nullable = false, length = 64)
    private String orderNo;

    /**
     * 用户ID
     */
    @Column(name = "user_id", nullable = false)
    private Long userId;

    /**
     * 支付金额
     */
    @Column(name = "amount", nullable = false, precision = 10, scale = 2)
    private BigDecimal amount;

    /**
     * 支付方式
     * ALIPAY: 支付宝
     * WECHAT: 微信支付
     * MOCK: 模拟支付（用于测试）
     */
    @Column(name = "payment_method", nullable = false, length = 32)
    private String paymentMethod;

    /**
     * 支付状态
     * PENDING: 待支付
     * SUCCESS: 支付成功
     * FAILED: 支付失败
     * CANCELLED: 已取消
     */
    @Column(name = "status", nullable = false, length = 32)
    private String status;

    /**
     * 第三方支付流水号
     */
    @Column(name = "third_party_transaction_no", length = 128)
    private String thirdPartyTransactionNo;

    /**
     * 支付时间
     */
    @Column(name = "payment_time")
    private LocalDateTime paymentTime;

    /**
     * 备注
     */
    @Column(name = "remark", length = 500)
    private String remark;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt;
}

